package dsg.graphdb.www.web;


import dsg.graphdb.www.entity.AjaxResult;
import com.vesoft.nebula.client.graph.SessionPool;
import com.vesoft.nebula.client.graph.SessionPoolConfig;
import com.vesoft.nebula.client.graph.data.HostAddress;
import com.vesoft.nebula.client.graph.data.ResultSet;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author yyyangyang@didichuxing.com
 * @date 2020-11-15
 */
@RestController
public class TestController {


    @GetMapping("/")
    public String index() {
        return "Hello Spring Boot 2.0!";
    }

    @GetMapping("/test")
    public AjaxResult test() {

        List<HostAddress> addresses = Arrays.asList(new HostAddress("182.92.81.151", 9669));
        String spaceName = "basketballplayer";
        String user = "root";
        String password = "nebula";
        SessionPoolConfig sessionPoolConfig = new SessionPoolConfig(addresses, spaceName, user, password);
        SessionPool sessionPool = new SessionPool(sessionPoolConfig);
        if (!sessionPool.init()) {
            System.out.println("session pool init failed.");
            return AjaxResult.error("session pool init failed.");
        }
        ResultSet resultSet;
        try {
            resultSet = sessionPool.execute("match (v) return v limit 100;");
            System.out.println(resultSet);
            return AjaxResult.success(resultSet);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        } finally {
            sessionPool.close();
        }
        return AjaxResult.error("session pool init failed.");
    }

    @GetMapping("get")
    public void get(Long id){
//        Iterable<RelationShip> all = relationShipRepository.findAll();
////        Optional<RelationShip> byId = relationShipRepository.findById(id);
//        return null;
    }

    public static void main(String[] args) {
        TestController testController = new TestController();
        testController.test();
    }

}
